#ifndef _GOVT_QUEST_HPP_
#define _GOVT_QUEST_HPP_

/*******************************************************************************
 ** Name: quest.hpp                                                           **
 ** Description:                                                              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved CDDL License                        **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry Gian James  <bjames@gamingods.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       **
 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED **
 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           **
 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT        **
 ** HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    **
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  **
 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    **
 ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    **
 ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      **
 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        **
 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              **
 **                                                                           **
 ******************************************************************************/
// Portions (c) 2011-2012 Open Design Strategies, LLC.
// Created on April 4, 2010, 10:03 AM
// Modified $Date$ by $Author$
#define quest_hpp_ID   "$Id$"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <odb/core.hxx>
#include <string>
#include <map>
#include "common.hpp"


// Types of motivation for NPCs (mostly wrt assignments and missions)
enum class NPCQuestMotivation : uint8_t {
	Knowledge, Comfort, Reputation, Serenity, Protection,
	Conquest, Wealth, Ability, Items
};

enum class AtomicQuestActions : int {
	Unknown = 0,
	Done = 1, Capture = 2, Damage = 3, Defend = 4, Escort = 5,
	Exchange = 6, Experiment = 7, Explore = 8, Gather = 9,
	Give = 10, Goto = 11, Kill = 12, Listen = 13, Read = 14,
	Repair = 15, Report = 16, Spy = 17, Stealth = 18, Take = 19,
	Use = 20
};

enum class QuestObjectiveType
{
	Item, Mob, Boss, Intangible
};

#pragma db value
struct QuestObjective
{
	QuestObjectiveType	type;
	uint8_t				num;	// number of items or kills
	entity_t			objective;
};

#pragma db object table("quests")
class Quest
{
public:
	SMART_PTR_DECL(Quest);

	Quest();
	virtual ~Quest() { }

	virtual void	GenObjectives();

	// Getters
	const entity_t	ID() const { return _id; }
	const uint8_t	ThreatLevel() const { return _qtl; }
	const std::string & Name() const { return _name; }
	const std::string & Tag() const { return _tag; }
	const std::string & Desc() const { return _desc; }
	const entity_t Next() const { return _next; }
	const NPCQuestMotivation	Motivation() const { return _motivation; }
	const unsigned int		XP() const { return _xp; }
	const QuestObjective & Objective() const { return _objective; }
	const entity_t	Giver() const { return _giver; }

	// Setters
	void	Tag(const std::string & t) { _tag = t; }
	void	ThreatLevel(const uint8_t t) { _qtl = t; }
	void	Desc(const std::string & s) { _desc = s; }
	void	Next(const entity_t e) { _next = e; }
	void	Name(const std::string & n) { _name = n; }
	void	XP(const unsigned int x) { _xp = x; }
	void	Objective(QuestObjectiveType t, uint8_t n, entity_t o) {
		_objective.type = t;
		_objective.num = n;
		_objective.objective = o;
	}
	void	Giver(const entity_t t) { _giver = t; }

private:
	friend class odb::access;

	#pragma db id auto
	entity_t		_id;
	uint8_t			_qtl;	// quest threat level
	std::string		_name;
#pragma db type ("VARCHAR(32)")
	std::string		_tag;
	entity_t		_next;
	std::string		_desc;
	unsigned int	_xp;
	entity_t		_giver;

	NPCQuestMotivation	_motivation;
	QuestObjective	_objective;

};

// For storage of player quests completed and in progress
#pragma db object table("character_quests")
struct PlayerQuest
{
	SMART_PTR_DECL(PlayerQuest);

#pragma db id auto
	entity_t	id_;
	entity_t	player_;
	entity_t	quest_;
	int			num_;	// how many out of the num required completed
	bool		completed_;
	std::map<std::string,std::string> _properties;

	void		AddProperty(const std::string & k, const std::string &v) { _properties[k] = v; }
	std::string &	GetProperty(const std::string & k) { return _properties[k]; }
};



#endif /* _GOVT_QUEST_HPP_ */
